package org.dormi.learn.product.port.web.product;

import org.dormi.learn.utils.TrackingUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class ProductController {

    private Logger log = LoggerFactory.getLogger(ProductController.class);

    @RequestMapping("/product")
    public String testFreemarker(ModelMap modelMap) {
        return "product/index";
    }

    @RequestMapping("/product/list")
    public String list(ModelMap modelMap) {
        return "product/index";
    }

    @RequestMapping("/product/create")
    public String displayCreate(ModelMap modelMap) {
        return "product/create";
    }

    @PostMapping(value = "/product/action/create", consumes = {MediaType.APPLICATION_JSON_VALUE})
    public String actionCreate(@RequestBody String body) {
        TrackingUtils.debugTrace();
        log.info(body);

        return "product/create";
    }
}